﻿using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
using WMS.FC.Domain.DomainObject.System;
using WMS.FC.Infrastructure.Common;

namespace WMS.FC.Infrastructure.Register
{
    public static class EFCoreRegister
    {
        public static void RegisterEFCore(this WebApplicationBuilder builder, WmsSettings wmsSettings)
        {
            builder.Services.AddDbContext<WmsDbContext>(options =>
            {
                options.EnableSensitiveDataLogging();
                options.LogTo(Log.Logger.Information, LogLevel.Information);
                options.LogTo(Log.Logger.Error, LogLevel.Error);
                options.ReplaceService<IMigrationsSqlGenerator, OracleMigrationsSqlGeneratorFix>();
                options.UseOracle(wmsSettings.GetOracleConnecitonString(), builder => builder.UseOracleSQLCompatibility("12"));
            });
        }
    }
}
